package Task42;

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();
            Stack<Integer> s = new Stack<>();
            for(int i = 0;i < n;i++) {
                String str = sc.next();
                char ch = str.charAt(0);
                if(!(str.equals("+")||str.equals("-")||str.equals("*")||str.equals("/"))) {
                    //数字
                    s.add(Integer.parseInt(str));//字符转化为数字
                }else{
                    //运算符
                    int right = s.pop();
                    int left = s.pop();

                    switch(ch){
                        case '+':
                            s.add(left + right);
                            break;
                        case '-':
                            s.add(left - right);
                            break;
                        case '*':
                            s.add(left * right);
                            break;
                        case '/':
                            s.add(left / right);
                            break;
                    }
                }
            }
            System.out.println(s.peek());
        }
    }
}
